<template>
  <div class="settings-container">
    <el-card>
      <div slot="header">
        <el-breadcrumb separator-class="el-icon-arrow-right">
          <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item>个人设置</el-breadcrumb-item>
        </el-breadcrumb>
      </div>
      <el-row>
        <el-col :span="12">
          <el-form size="small" ref="form" :model="userForm" label-width="80px">
            <el-form-item label="编号">
              {{userForm.id}}
            </el-form-item>
            <el-form-item label="手机">
              {{userForm.mobile}}
            </el-form-item>
            <el-form-item label="媒体名称">
              <el-input v-model="userForm.name"></el-input>
            </el-form-item>
            <el-form-item label="媒体介绍">
              <el-input v-model="userForm.intro"></el-input>
            </el-form-item>
            <el-form-item label="邮箱">
              <el-input v-model="userForm.email"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="save">保存设置</el-button>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :offset="4" :span="8">
          <el-image
            style="width: 150px; height: 150px"
            :src="userForm.photo"
            fit="cover"
          ></el-image>
        </el-col>
      </el-row>
    </el-card>
  </div>
</template>

<script>
import { getUserInfo, editUserInfo } from '@/api/user'
export default {
  name: "Settings",
  data() {
    return {
      userForm: {}, // 用户信息表单
    };
  },
  methods: {
    // 获取用户信息
    getUserInfo() {
      getUserInfo().then(res => {
        this.userForm = res.data.data
      })
    },
    // 保存用户信息
    save() {
      // 表单验证成功之后发送请求
      editUserInfo(this.userForm).then(res => {
        this.$message.success("修改成功！");
        // 发布事件总线，通知顶部导航更改信息
        this.$EventBus.$emit('update-user', this.userForm)
      })
    }
  },
  created() {
    // 获取用户信息
    this.getUserInfo()
  }
};
</script>

<style lang="less" scope>
</style>
